package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.FSKCSMOperate;
import com.log.LatteLogger;

public class CSMDevice
{
  private String deviceType;
  private String comNo;
  private String baudRate;
  
  public CSMDevice(String devType, String com, String brn)
  {
    this.deviceType = devType;
    this.comNo = com;
    this.baudRate = brn;
  }

  public String getDeviceType() {
    return deviceType;
  }

  public String getComNo() {
    return comNo;
  }

  public String getBaudRate() {
    return baudRate;
  }

  public int beginCSM()
  {
    int return_data = 0;
    try
    {
      if ("FSK1".equals(getDeviceType()))
      {
        FSKCSMOperate.comNo = this.comNo;
        FSKCSMOperate.baudRate = this.baudRate;
        
        return_data = FSKCSMOperate.beginCSM();
        LatteLogger.d("压缩机状态码",return_data);
      }
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
      LatteLogger.e("压缩机异常", ex.getMessage());
      LogUtil.writeExceptionLog("开启压缩机异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int closeCSM()
  {
    int return_data = 0;
    try
    {
      if ("FSK1".equals(getDeviceType()))
      {
        FSKCSMOperate.comNo = this.comNo;
        FSKCSMOperate.baudRate = this.baudRate;
        
        return_data = FSKCSMOperate.closeCSM();
        LatteLogger.d("压缩机关闭",return_data);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("关闭压缩机异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int allCloseCSM()
  {
    int return_data = 0;
    try
    {
      if ("FSK1".equals(getDeviceType()))
      {
        FSKCSMOperate.comNo = this.comNo;
        FSKCSMOperate.baudRate = this.baudRate;
        
        return_data = FSKCSMOperate.allCloseCSM();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("关闭设备异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int tempCheckCSM()
  {
    int return_data = 0;
    try
    {
      if ("FSK1".equals(getDeviceType()))
      {
        FSKCSMOperate.comNo = this.comNo;
        FSKCSMOperate.baudRate = this.baudRate;
        
        return_data = FSKCSMOperate.tempCheckCSM();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("关闭设备异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
}
